﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace GuiSearcher.Converters {
    public class DoubleToStringConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            if (value == null || !(value is double))
                return value;
            return ((double)value).ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            if (value == null || !(value is string))
                return value;
            double result;
            bool canConvert = double.TryParse((string)value, out result);
            if (canConvert) {
                return result;
            }
            else {
                return null;
            }
            
        }
    }
}
